    using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Fieldbook.Business;

namespace Fieldbook.Testwebsite.User
{
    public class FieldMapGenerator : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Expires = -1000; // we don't want our browser to cashe this image
            context.Response.ContentType = "image/jpeg";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;
            
            string path = context.Server.MapPath("../FieldMaps");
            long userID = Int64.Parse(context.Request["userID"]);
            int mapID = Int32.Parse(context.Request["mapID"]);

            Stream fs = ImageGenerator.GenerateMapImage(userID, mapID, path);
            const int buffersize = 1024 * 16;
            byte[] buffer = new byte[buffersize];
            int count = fs.Read(buffer, 0, buffersize);
            while (count > 0)
            {
                context.Response.OutputStream.Write(buffer, 0, count);
                count = fs.Read(buffer, 0, buffersize);
            }
            fs.Close();

            // proveri da li jos treba setovati da je Output MULTIPART MIME ili tako nesto... 
        }
        #endregion
    }
}
